package com.example.testscalaandroid2.act

import org.scaloid.common.SActivity
import org.scaloid.common.SVerticalLayout
import org.scaloid.common.SRelativeLayout
import org.scaloid.common.STextView
import org.scaloid.common.SEditText
import java.util.AbstractCollection
import android.view.View
import org.scaloid.common.Implicits
import org.scaloid.common.SLinearLayout
import org.scaloid.common.SRadioGroup
import org.scaloid.common.TraitViewGroup
import org.scaloid.common.SRadioButton
import org.scaloid.common.TraitView
import org.scaloid.common.SCheckBox
import org.scaloid.common.SSpinner
import org.scaloid.common.SArrayAdapter
import org.scaloid.common.SButton
import android.text.InputType
import org.scaloid.common.AlertDialogBuilder
import android.graphics.Color
class UserLoginAct extends SActivity with Implicits {
  onCreate {

    contentView = new SVerticalLayout {
      style {
        case tv: STextView => tv.<<.wrap.>>.width(70.dip)
        case txt: SEditText => txt.<<.wrap.>>.textSize(11.sp).width(250.dip).textColor(Color.BLACK)
        case t: SRadioGroup => t.<<.wrap.>>
        case t: SRadioButton => t.<<.wrap.>>
        case t: SCheckBox => t.<<.wrap.>>
      }
      implicit val tvg = this

      abstract class FieldLayout(name: String)(implicit tvg: TraitViewGroup[_]) extends SLinearLayout {
        type G <: TraitView[_] with View
        //orientation = HORIZONTAL
        val tv = STextView(name)
        val t = ttt

        def create: G
        def ttt = {
          val t = create
          t //.rightOf(tv).alignTop(tv).>>
        }
        tvg += this

      }
      class StrLO(name: String) extends FieldLayout(name) {
        type G = SEditText
        def create = SEditText()
      }

      val name = new StrLO("name:")
      val pwd = new StrLO("pwd:")
      pwd.t.inputType(TEXT_PASSWORD)
      val age = new StrLO("age:")
      age.t.inputType(InputType.TYPE_CLASS_NUMBER)

      val sex = new FieldLayout("gender:") {
        class SexGroup extends SRadioGroup {
          orientation = HORIZONTAL
          //          val m = new SRadioButton("man").checked(true)
          //          val w = new SRadioButton("woman")
          //          this += m
          //          this += w
          SRadioButton("man").checked(true)
          SRadioButton("woman")
        }
        type G = SexGroup
        def create = {
          val t = new SexGroup
          this += t
          t
        }
      }
      val likes = new FieldLayout("likes") {
        class Likes extends SLinearLayout {
          orientation = HORIZONTAL
          val book = SCheckBox("book")
          val ball = SCheckBox("ball")
          val sex = SCheckBox("sex")
          val wtf = SCheckBox("wtf")
        }
        type G = Likes
        def create = {
          val t = new G
          this += t
          t
        }
      }

      val city = new FieldLayout("city") {
        type G = SSpinner
        def create = SSpinner().prompt("what?").adapter(SArrayAdapter("a", "b", "c"))
      }
      SButton("reg", reg).padding(20)

      def reg = {
        if (List(name, age, pwd).forall { t =>
          if (t.t.text.toString().isEmpty()) {
            t.t.error("cant empty")
            false
          } else true
        })
          new AlertDialogBuilder("title", s"?????") {
            neutralButton(onClick = { spinnerDialog("reging", "wait...") })
            negativeButton()
          }.show()

      }
    }

  }
}



